﻿using System;
using System.Collections.Generic;
using MugenInjection.Delegates;
using MugenInjection.Infrastructure;
using MugenInjection.Interface;

// ReSharper disable CheckNamespace
namespace MugenInjection.Core.Components
// ReSharper restore CheckNamespace
{
    /// <summary>
    ///     Represents the converter to convert all types in direct injector call.
    /// </summary>
    public class SimpleConverter : ConverterBase
    {
        #region Constructors

        /// <summary>
        ///     Initializes a new instance of the <see cref="SimpleConverter" /> class.
        /// </summary>
        public SimpleConverter()
            : base(int.MinValue, ServiceType.Simple)
        {
        }

        #endregion

        #region Overrides of ConverterBase

        /// <summary>
        ///     Gets the supported types.
        /// </summary>
        public override IEnumerable<Type> SupportedTypes
        {
            get { return InjectorUtils.EmptyTypes; }
        }

        /// <summary>
        ///     Tries to convert instance.
        /// </summary>
        /// <param name="bindingContext">The specified type to convert from.</param>
        /// <param name="originalType">The type to convert to.</param>
        /// <param name="convertAction">An delegate to convert instance.</param>
        /// <returns>
        ///     If <c>true</c> can be converted; otherwise <c>false</c>.
        /// </returns>
        protected override ConverterResult TryConvertInternal(IBindingContext bindingContext, out Type originalType, out Func<object, object> convertAction)
        {
            convertAction = null;
            originalType = bindingContext.Service;
            return ConverterResult.SupportedWithCache;
        }

        #endregion
    }
}